package com.hcb.tonguetiphealth.widget.recommendhealth;

import java.util.ArrayList;
import java.util.List;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONArray;
import org.json.JSONObject;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Handler;
import android.os.Message;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.text.TextPaint;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RatingBar;
import android.widget.RatingBar.OnRatingBarChangeListener;
import android.widget.TextView;

import com.hcb.tonguetiphealth.adapter.GeneralPageAdapter;
import com.hcb.tonguetiphealth.global.Global;
import com.hcb.tonguetiphealth.manager.JSONManager;
import com.hcb.tonguetiphealth.model.HealthCate;
import com.hcb.tonguetiphealth.model.HealthCateComment;
import com.hcb.tonguetiphealth.model.User;
import com.hcb.tonguetiphealth.util.HttpUtils;
import com.hcb.tonguetiphealth.util.MessageWhat;
import com.hcb.tonguetiphealth.util.StringUtils;
import com.hcb.tonguetiphealth.view.ChatActivity;
import com.hcb.tonguetiphealth.view.MoreActivity;
import com.hcb.tonguetiphealth.view.R;
import com.hcb.tonguetiphealth.widget.GeneralWidget;

public class RecommendHealthHealthCateInfoWidget extends GeneralWidget implements OnClickListener {
	private static final String TAG = "RecommendHealthHealthCateInfoWidget";
	private String url_healthCateMessage = Global.URL + Global.servlet_healthCateMessage;
	private String url_healthCateComment = Global.URL + Global.servlet_healthCateComment;
	private String url_getHealthCateComments = Global.URL + Global.servlet_getHealthCateComments;
	
	private Activity ctx;
	private LayoutInflater inflater;
	private Handler mHandler;
	private HealthCate crrentHealthCate;
	private List<HealthCate> healthCateList;
	private ImageView iv, iv1, iv2, iv3, iv4, iv5, iv6, iv_content, iv_reason, iv_suitbale, iv_unsuited;
	
	private TextView tv_name, tv_downCount, tv_comment, tv_content, tv_reason, tv_suitbale, tv_unsuited;
	private RatingBar ratingBar, ratingBar2;
	private Button bt_comment, bt_share, bt_mesphone, bt_chat;
	private LinearLayout ll_back, ll_content, ll_reason, ll_suitbale, ll_unsuited, 
											ll_content_tv, ll_reason_tv, ll_suitbale_tv, ll_unsuited_tv, ll_comment;
	private List<HealthCateComment> HealthCateCommentList;
	
	private int crrentPageId = 0;
	private ViewPager viewPager;
	private List<View> pageViews;
	private View view;
	private GeneralPageAdapter pageAdapter;
	
	private AlertDialog dalog;
	private int level;
	
	public RecommendHealthHealthCateInfoWidget(Context context) {
		super(context);
		ctx = (Activity)context;
		crrentHealthCate = (HealthCate)ctx.getIntent().getSerializableExtra("healthCate");
		healthCateList = Global.healthCateList;
				
		inflater = ctx.getLayoutInflater();
		inflate(context, R.layout.recommend_health_health_cate_info, this); 
		
		iv = (ImageView)findViewById(R.id.health_cate_info_main_img);
		iv_content = (ImageView)findViewById(R.id.health_cate_info_content_img);
		iv_reason = (ImageView)findViewById(R.id.health_cate_info_reason_img);
		iv_suitbale = (ImageView)findViewById(R.id.health_cate_info_suitable_img);
		iv_unsuited = (ImageView)findViewById(R.id.health_cate_info_unsuited_img);
		
		tv_name = (TextView)findViewById(R.id.health_cate_info_name_textview);
		TextPaint tp = tv_name.getPaint(); 
		tp.setFakeBoldText(true); 
		tv_downCount = (TextView)findViewById(R.id.health_cate_info_downcunt_textview);
		tv_comment = (TextView)findViewById(R.id.health_cate_info_comment_textview);
		tv_content = (TextView)findViewById(R.id.health_cate_info_content_textview);
		tv_reason = (TextView)findViewById(R.id.health_cate_info_reason_textview);
		tv_suitbale = (TextView)findViewById(R.id.health_cate_info_suitable_textview);
		tv_unsuited = (TextView)findViewById(R.id.health_cate_info_unsuited_textview);

		ratingBar = (RatingBar)findViewById(R.id.health_cate_info_ratings_ratingbar);
		ratingBar2 = (RatingBar)findViewById(R.id.health_cate_info_comment_ratings_ratingbar);
		
		bt_comment = (Button)findViewById(R.id.health_cate_info_comment_button);
		bt_share = (Button)findViewById(R.id.health_cate_info_share_button);
		bt_mesphone = (Button)findViewById(R.id.health_cate_info_mesphone_button);
		bt_chat = (Button)findViewById(R.id.health_cate_info_chat_button);

		ll_back = (LinearLayout)findViewById(R.id.health_cate_info_back_button);
		ll_content = (LinearLayout)findViewById(R.id.health_cate_info_content_linearlayout_button);
		ll_reason = (LinearLayout)findViewById(R.id.health_cate_inf_reason_linearlayout_button);
		ll_suitbale = (LinearLayout)findViewById(R.id.health_cate_info_suitable_linearlayout_button);
		ll_unsuited = (LinearLayout)findViewById(R.id.health_cate_info_unsuited_linearlayout_button);
		ll_content_tv = (LinearLayout)findViewById(R.id.health_cate_info_content_linearlayout);
		ll_reason_tv = (LinearLayout)findViewById(R.id.health_cate_info_reason_linearlayout);
		ll_suitbale_tv = (LinearLayout)findViewById(R.id.health_cate_info_suitable_linearlayout);
		ll_unsuited_tv = (LinearLayout)findViewById(R.id.health_cate_info_unsuited_linearlayout);
		ll_comment = (LinearLayout)findViewById(R.id.health_cate_info_comment_linearlayout);

		bt_comment.setOnClickListener(this);
		bt_share.setOnClickListener(this);
		bt_mesphone.setOnClickListener(this);
		bt_chat.setOnClickListener(this);
		ll_back.setOnClickListener(this);
		ll_content.setOnClickListener(this);
		ll_reason.setOnClickListener(this);
		ll_suitbale.setOnClickListener(this);
		ll_unsuited.setOnClickListener(this);
		ratingBar2.setOnRatingBarChangeListener(new OnRatingBarChangeListener() {
			@Override
			public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) {
				// TODO Auto-generated method stub
				switch((int)rating) {
				case 0:
				case 1:
					tv_comment.setText(R.string.health_personal_cate_comment_level_01);
					break;
				case 2:
					tv_comment.setText(R.string.health_personal_cate_comment_level_2);
					break;
				case 3:
					tv_comment.setText(R.string.health_personal_cate_comment_level_3);
					break;
				case 4:
					tv_comment.setText(R.string.health_personal_cate_comment_level_4);
					break;
				case 5:
					tv_comment.setText(R.string.health_personal_cate_comment_level_5);
					break;
				default:
					tv_comment.setText("");
					break;
				}
			}
		});
		
		viewPager = (ViewPager)findViewById(R.id.health_cate_info_viewpager);
		
		mHandler = new Handler() {
			@Override
			public void handleMessage(Message msg) {
				switch(msg.what) {
				case MessageWhat.SHOW_DIALOG:
					showMessageDialog(ctx, "正在登陆...");
					break;
				case MessageWhat.DIMISS_DIALOG:
					dismissMessageDialog();
					break;
				case MessageWhat.COMMIT_SUCCEED:
					ratingBar2.setRating(0);
					tv_comment.setText("");
					initHealthCateInfo();
					dismissMessageDialog();
					break;
				case MessageWhat.COMMIT_FAILD:
					initHealthCateInfo();
					dismissMessageDialog();
					break;
				case MessageWhat.GETWINEINFO_SUCCEED:
					initHealthCateInfo();
					break;
				case MessageWhat.GETWINEINFO_FAILED:
					initHealthCateInfo();
					break;
				case MessageWhat.MSG_SEND_ING:
					showMessageDialog(ctx, "发送短信到手机...");
					break;
				case MessageWhat.MSG_SEND_SUCCEED:
					showMessage(ctx, "短信发送成功");
					dismissMessageDialog();
					break;
				case MessageWhat.MSG_SEND_FAILD:
					showMessage(ctx, "短信发送失败");
					dismissMessageDialog();
					break;
				}
			}
			
		};
		HealthCateCommentList = new ArrayList<HealthCateComment>();
		initHealthCateInfo();
		initDataPageView();
	}
	public void onClick(View v) {
		switch(v.getId()) {
		case R.id.health_cate_info_comment_button:
			level = (int)ratingBar2.getRating();
			if(Global.user == null) {
				login();
			} else if(level == 0 || level == 1) {
				showCommenttDialog();
			} else {
				comment();
			}
			break;
		case R.id.health_cate_info_share_button:
			if(Global.user == null) {
				login();
			} else {
				Intent intent = new Intent(ctx, MoreActivity.class);
				intent.putExtra("do", "share");
				ctx.startActivity(intent);
			}
			break;
		case R.id.health_cate_info_mesphone_button:
			if(Global.user == null) {
				login();
			} else {
				showTelDialog();
			}
			break;
		case R.id.health_cate_info_chat_button:
			if(Global.user == null) {
				showMessage(ctx, "请登录!");
				login();
			} else if(Global.user.getUserName().equals(crrentHealthCate.getUser().getUserName())) {
				showMessage(ctx, "不可与自己私信互动");
			} else {
				Intent intent = new Intent(ctx, ChatActivity.class);
				intent.putExtra("user", crrentHealthCate.getUser());
				intent.putExtra("from", "user");
				ctx.startActivity(intent);
			}
			break;
		case R.id.health_cate_info_back_button:
			ctx.setContentView(new RecommendHealthWidget(ctx));
			break;
		case R.id.health_cate_info_content_linearlayout_button:
			if(ll_content_tv.getVisibility() == LinearLayout.GONE) {
				ll_content_tv.setVisibility(LinearLayout.VISIBLE);
				iv_content.setBackgroundResource(R.drawable.list_more_up);
			} else {
				ll_content_tv.setVisibility(LinearLayout.GONE);
				iv_content.setBackgroundResource(R.drawable.list_more);
			}
			break;
		case R.id.health_cate_inf_reason_linearlayout_button:
			if(ll_reason_tv.getVisibility() == LinearLayout.GONE) {
				ll_reason_tv.setVisibility(LinearLayout.VISIBLE);
				iv_reason.setBackgroundResource(R.drawable.list_more_up);
			} else {
				ll_reason_tv.setVisibility(LinearLayout.GONE);
				iv_reason.setBackgroundResource(R.drawable.list_more);
			}
			break;
		case R.id.health_cate_info_suitable_linearlayout_button:
			if(ll_suitbale_tv.getVisibility() == LinearLayout.GONE) {
				ll_suitbale_tv.setVisibility(LinearLayout.VISIBLE);
				iv_suitbale.setBackgroundResource(R.drawable.list_more_up);
			} else {
				ll_suitbale_tv.setVisibility(LinearLayout.GONE);
				iv_suitbale.setBackgroundResource(R.drawable.list_more);
			}
			break;
		case R.id.health_cate_info_unsuited_linearlayout_button:
			if(ll_unsuited_tv.getVisibility() == LinearLayout.GONE) {
				ll_unsuited_tv.setVisibility(LinearLayout.VISIBLE);
				iv_unsuited.setBackgroundResource(R.drawable.list_more_up);
			} else {
				ll_unsuited_tv.setVisibility(LinearLayout.GONE);
				iv_unsuited.setBackgroundResource(R.drawable.list_more);
			}
			break;
		default:
			initCateInfo(v.getId());
			break;
		}
	}
	private void initCateInfo(int id) {
		int num = 0;
		switch(id) {
		case R.id.drinks_book_drink_info_pageview_img1:
			num += 0;
			break;
		case R.id.drinks_book_drink_info_pageview_img2:
			num += 1;
			break;
		case R.id.drinks_book_drink_info_pageview_img3:
			num += 2;
			break;
		case R.id.drinks_book_drink_info_pageview_img4:
			num += 3;
			break;
		case R.id.drinks_book_drink_info_pageview_img5:
			num += 4;
			break;
		case R.id.drinks_book_drink_info_pageview_img6:
			num += 5;
			break;
		}
		int position = crrentPageId*6 + num;
		HealthCate healthCate = healthCateList.get(position);
		if(healthCate.isCurrent()) {
			//showMessage(ctx, "已是当前套餐详情");
		} else {
			crrentHealthCate.setCurrent(false);
			crrentHealthCate = healthCate;
			crrentHealthCate.setCurrent(true);
			
			downLoadComments();
		}
	}
	private void initHealthCateInfo() {
		loadImage(iv, crrentHealthCate.getUser().getImgUrl());
		tv_name.setText(crrentHealthCate.getUser().getUserName());
		ratingBar.setRating(crrentHealthCate.getLevel());
		tv_downCount.setText(crrentHealthCate.getDownCount() +"");
		tv_content.setText("\t\t" + crrentHealthCate.getContent());
		tv_reason.setText("\t\t" + crrentHealthCate.getReason());
		tv_suitbale.setText("\t\t" + crrentHealthCate.getSuitable());
		tv_unsuited.setText("\t\t" + crrentHealthCate.getUnsuited());
		
		if(HealthCateCommentList.size() > 0) {
			ll_comment.removeAllViews();
			ll_comment.setVisibility(LinearLayout.VISIBLE);
			for(HealthCateComment comment : HealthCateCommentList) {
				view = inflater.inflate(R.layout.health_cate_comment_list_item, null);
				TextView tv_name = (TextView)view.findViewById(R.id.health_cate_comment_name_textview);
				TextView tv_time = (TextView)view.findViewById(R.id.health_cate_comment_time_textview);
				TextView tv_content = (TextView)view.findViewById(R.id.health_cate_comment_textview);
				RatingBar rating = (RatingBar)view.findViewById(R.id.health_cate_comment_ratings_ratingbar);
				tv_name.setText(comment.getUser().getUserName());
				tv_time.setText(comment.getDate());
				int level = (int)comment.getLevel();
				rating.setRating(level);
				switch(level) {
				case 0:
				case 1:
					tv_content.setText(R.string.health_personal_cate_comment_level_01);
					break;
				case 2:
					tv_content.setText(R.string.health_personal_cate_comment_level_2);
					break;
				case 3:
					tv_content.setText(R.string.health_personal_cate_comment_level_3);
					break;
				case 4:
					tv_content.setText(R.string.health_personal_cate_comment_level_4);
					break;
				case 5:
					tv_content.setText(R.string.health_personal_cate_comment_level_5);
					break;
				default:
					tv_content.setText("");
					break;
				}
				ll_comment.addView(view);
			}
		} else {
			ll_comment.setVisibility(LinearLayout.GONE);
		}
	}
	private void showCommenttDialog() {
		AlertDialog.Builder builder = new AlertDialog.Builder(ctx);
		builder.setTitle("评论提示");
		//builder.setIcon(R.drawable.what);
		builder.setMessage("评分 " + level + " 为【不推荐】，确定评论？");
		builder.setCancelable(false);
		builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
			public void onClick(DialogInterface dialog, int id) {
				comment();
			}
		});
		builder.setNegativeButton("取消", null);
		builder.show();
	}
	private void comment() {
		showMessageDialog(ctx, "正在提交评论...");
		new Thread() {
			public void run() {
				String response = null;
				try {
					List <NameValuePair> params = new ArrayList <NameValuePair>();
					params.add(new BasicNameValuePair("id", crrentHealthCate.getId()));
					params.add(new BasicNameValuePair("userid", Global.user.getUserId()));
					params.add(new BasicNameValuePair("level", level +""));
					response = HttpUtils.Post(url_healthCateComment, params);
					if(Global.DEBUG) { 
						System.out.println( "comment -----------------------------\n" + response);
					}
				} catch(Exception e) {
					Log.e(TAG, "Exception", e);
				}
				if(!StringUtils.isEmpty(response)) {
					JSONManager jManager = new JSONManager();
					boolean isGotJSONObject = jManager.isGotJSONObject(response);
					if(isGotJSONObject) {
						
						int count = jManager.getResult();
						String msg = jManager.getMsg();
						System.out.println("------ 得到msg: " + count + ":" + msg);
						
						HealthCateComment comment = new HealthCateComment();
						comment.setId("");
						comment.setLevel(level);
						comment.setAddTime(System.currentTimeMillis()/1000);
						comment.setUser(Global.user);
						HealthCateCommentList.add(comment);

						mHandler.sendEmptyMessage(MessageWhat.COMMIT_SUCCEED);
					} else {
						mHandler.sendEmptyMessage(MessageWhat.COMMIT_FAILD);
					}
				} else {
					mHandler.sendEmptyMessage(MessageWhat.COMMIT_FAILD);
				}
			}
		}.start();
	}
	
	private void downLoadComments() {
		HealthCateCommentList.clear();
		new Thread() {
			public void run() {
				String response = null;
				try {
					List <NameValuePair> params = new ArrayList <NameValuePair>();
					params.add(new BasicNameValuePair("id", crrentHealthCate.getId()));
					response = HttpUtils.Post(url_getHealthCateComments, params);
					if(Global.DEBUG) { 
						System.out.println("downLoadComments -----------------------------\n" + response);
					}
				} catch(Exception e) {
					Log.e(TAG, "Exception", e);
				}
				if(!StringUtils.isEmpty(response)) {
					JSONManager jManager = new JSONManager();
					boolean isGotJSONObject = jManager.isGotJSONObject(response);
					if(isGotJSONObject) {
						HealthCateComment comment;
						JSONArray jList = jManager.getJsonList();
						if(null == jList) {
							
						} else {
							for(int i=0; i< jList.length(); i++) {
								JSONObject jObject = getJSONObject(jList, i);
								if(null != jObject) {
									comment = new HealthCateComment();
									comment.setId(getString(jObject, "id"));
									comment.setLevel(StringUtils.parseFloat(getString(jObject, "level")));
									comment.setAddTime(StringUtils.parseLong(getString(jObject, "addtime")));
									
									User user = new User();
									user.setUserId(getString(jObject, "userid"));
									user.setUserName(getString(jObject, "username"));
									user.setImgUrl(getString(jObject, "headicon"));
									user.setRealName(getString(jObject, "truename"));
									comment.setUser(user);
									
									HealthCateCommentList.add(comment);
								}
							}
						}
						int count = jManager.getResult();
						String msg = jManager.getMsg();
						System.out.println("------ 得到msg: " + count + ":" + msg);
					}
				}
				mHandler.sendEmptyMessage(MessageWhat.GETWINEINFO_SUCCEED);
			}
		}.start();
	}

	private void showTelDialog() {
		AlertDialog.Builder builder = new AlertDialog.Builder(ctx);
        dalog = builder.create();
     // 获取自定义布局  
    	LayoutInflater inflater = LayoutInflater.from(ctx);  
    	View view = inflater.inflate(R.layout.tel_edittext_dialog, null);  
    	final EditText et = (EditText)view.findViewById(R.id.tel_edittext_dialog_et);
    	et.setText(Global.user.getTel());
        et.setSelection(et.getText().length());
    	Button ok = (Button)view.findViewById(R.id.tel_edittext_dialog_ok_bt);
    	Button cancel = (Button)view.findViewById(R.id.tel_edittext_dialog_cancel_bt);
    	ok.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				String tel = et.getText().toString();
				if(IsValidMobileNo(tel)) {
					dalog.dismiss();
					sendMsgToPhone(tel);
				} else {
					showMessage(ctx, "请输入正确的手机号码");
				}
			}
		});
    	cancel.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				dalog.dismiss();
			}
		});
        dalog.setTitle("请输入电话号码");
		dalog.setView(view);
        dalog.show();
	}
	private void sendMsgToPhone(final String tel) {
		mHandler.sendEmptyMessage(MessageWhat.MSG_SEND_ING);
		new Thread() {
			public void run() {
				String response = null;
				try {
					List <NameValuePair> params = new ArrayList <NameValuePair>();
					params.add(new BasicNameValuePair("userid", Global.user.getUserId()));
					params.add(new BasicNameValuePair("id", crrentHealthCate.getId()));
					params.add(new BasicNameValuePair("tel", tel));
					response = HttpUtils.Post(url_healthCateMessage, params);
					if(Global.DEBUG) { 
						System.out.println(" -----------------------------\n" + response);
					}
				} catch(Exception e) {
					Log.e(TAG, "Exception", e);
				}
				if(!StringUtils.isEmpty(response)) {
					JSONManager jManager = new JSONManager();
					boolean isGotJSONObject = jManager.isGotJSONObject(response);
					if(isGotJSONObject) {
						
						int count = jManager.getResult();
						String msg = jManager.getMsg();
						System.out.println("------ 得到msg: " + count + ":" + msg);
						mHandler.sendEmptyMessage(MessageWhat.MSG_SEND_SUCCEED);
					} else {
						mHandler.sendEmptyMessage(MessageWhat.MSG_SEND_FAILD);
					}
				} else {
					mHandler.sendEmptyMessage(MessageWhat.MSG_SEND_FAILD);
				}
			}
		}.start();
	}
	private void initDataPageView() {
		for(HealthCate cate : healthCateList) {
			if(cate.isCurrent()) {
				crrentHealthCate = cate;
				downLoadComments();
				break;
			}
		}
		pageViews = new ArrayList<View>();
		int pageCount = healthCateList.size()/6 + (healthCateList.size()%6 == 0?0:1);
		pageCount = pageCount>4? 4 : pageCount;
		for(int i=0; i< pageCount; i++) {
			pageViews.add(inflater.inflate(R.layout.drinks_book_drinks_info_pageview, null));
		}
		
		HealthCate cate;
		for(int i=0; i<pageViews.size(); i++) {
			view = pageViews.get(i);
			iv1 = (ImageView)view.findViewById(R.id.drinks_book_drink_info_pageview_img1);
			iv2 = (ImageView)view.findViewById(R.id.drinks_book_drink_info_pageview_img2);
			iv3 = (ImageView)view.findViewById(R.id.drinks_book_drink_info_pageview_img3);
			iv4 = (ImageView)view.findViewById(R.id.drinks_book_drink_info_pageview_img4);
			iv5 = (ImageView)view.findViewById(R.id.drinks_book_drink_info_pageview_img5);
			iv6 = (ImageView)view.findViewById(R.id.drinks_book_drink_info_pageview_img6);
			int count = healthCateList.size() - (i+1)*6;
			if(count >= 0) {
				for(int j=1; j<=6; j++) {
					cate = healthCateList.get(i*6 + j-1);
					initImage(j, cate);
				}
			} else {
				count = healthCateList.size() - i*6;
				for(int j=1; j<=count; j++) {
					cate = healthCateList.get(i*6 + j-1);
					initImage(j, cate);
				}
				switch(count) {
				case 1:
					iv2.setVisibility(ImageView.INVISIBLE);
					iv3.setVisibility(ImageView.INVISIBLE);
					iv4.setVisibility(ImageView.INVISIBLE);
					iv5.setVisibility(ImageView.INVISIBLE);
					iv6.setVisibility(ImageView.INVISIBLE);
					break;
				case 2:
					iv3.setVisibility(ImageView.INVISIBLE);
					iv4.setVisibility(ImageView.INVISIBLE);
					iv5.setVisibility(ImageView.INVISIBLE);
					iv6.setVisibility(ImageView.INVISIBLE);
					break;
				case 3:
					iv4.setVisibility(ImageView.INVISIBLE);
					iv5.setVisibility(ImageView.INVISIBLE);
					iv6.setVisibility(ImageView.INVISIBLE);
					break;
				case 4:
					iv5.setVisibility(ImageView.INVISIBLE);
					iv6.setVisibility(ImageView.INVISIBLE);
					break;
				case 5:
					iv6.setVisibility(ImageView.INVISIBLE);
					break;
				}
			}
			
		}
		
		pageAdapter = new GeneralPageAdapter(pageViews);
		viewPager.setAdapter(pageAdapter);
		viewPager.setOnPageChangeListener(new GuidePageChangeListener());
	}
	private void initImage(int id, HealthCate cate) {
		switch(id) {
		case 1:
			loadImage(iv1, cate.getUser().getImgUrl());
			iv1.setOnClickListener(this);
			break;
		case 2:
			loadImage(iv2, cate.getUser().getImgUrl());
			iv2.setOnClickListener(this);
			break;
		case 3:
			loadImage(iv3, cate.getUser().getImgUrl());
			iv3.setOnClickListener(this);
			break;
		case 4:
			loadImage(iv4, cate.getUser().getImgUrl());
			iv4.setOnClickListener(this);
			break;
		case 5:
			loadImage(iv5, cate.getUser().getImgUrl());
			iv5.setOnClickListener(this);
			break;
		case 6:
			loadImage(iv6, cate.getUser().getImgUrl());
			iv6.setOnClickListener(this);
			break;
		}
	}
	// 指引页面更改事件监听器
	class GuidePageChangeListener implements OnPageChangeListener {

		public void onPageScrollStateChanged(int arg0) {
		}

		public void onPageScrolled(int arg0, float arg1, int arg2) {
		}

		public void onPageSelected(int arg0) {
			crrentPageId = arg0;
			switch(arg0) {
			case 0:
				break;
			case 1:
				break;
			case 2:
				break;
			}
		}
	}
	@Override
	public void notifyAdapter() {
		
	}
}
